package com.sky.controller.admin;

import com.sky.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.time.LocalTime;

@Slf4j
@RestController
public class ShopController {

    private static Integer SysStatus;

    static {
        //营业时间
        LocalTime startTime = LocalTime.of(9, 0);
        //打烊时间
        LocalTime endTime = LocalTime.of(20, 0);
        //获取当前时间
        LocalTime nowTime = LocalTime.now();
        if (startTime.isBefore(nowTime) && endTime.isAfter(nowTime)) {
            SysStatus = 1;
        } else {
            SysStatus = 0;
        }
    }

    /**
     * 获取营业状态
     *
     * @return
     */
    @GetMapping("admin/shop/status")
    public Result<Integer> findStatus() {
        log.info("获取营业状态");
        return Result.success(SysStatus);
    }

    /**
     * C端获取营业状态
     *
     * @return
     */
    @GetMapping("/user/shop/status")
    public Result<Integer> findStatusOfC() {
        log.info("C端获取营业状态");
        return Result.success(SysStatus);
    }

    /**
     * 设置营业状态
     *
     * @param status
     * @return
     */
    @PutMapping("admin/shop/{status}")
    public Result<Integer> updateStatus(@PathVariable Integer status) {
        log.info("设置营业状态");
        SysStatus = status;
        return Result.success();
    }
}
